// pgis 瓦片解析配置(吴江)
export const wjPgisTileConfig = {
  projection: 'EPSG:4326',
  tileGrid: {
    origin: [0, 0],
    resolutions: [
      2,
      1,
      0.5,
      0.25,
      0.125,
      0.0625,
      0.03125,
      0.015625,
      0.0078125,
      0.00390625,
      0.001953125,
      0.0009765625,
      0.00048828125,
      0.000244140625,
      0.0001220703125,
      0.00006103515625,
      0.000030517578125,
      0.0000152587890625,
      0.00000762939453125,
      0.000003814697265625,
      0.0000019073486328125,
      0.00000095367431640625,
      0.000000476837158203125,
    ],
  },
  tileUrlFunction: function (tileCoord) {
    // 获取给定缩放级别的原点
    var origin = this.getTileGrid().getOrigin(tileCoord[0]);
    // 获取给定缩放级别的分辨率
    var res = this.getTileGrid().getResolution(tileCoord[0]);
    // 瓦片大小
    var tileSize = [256, 256];
    var minX = origin[0] + tileCoord[1] * tileSize[0] * res;
    var minY = origin[1] + tileCoord[2] * tileSize[1] * res;
    var maxX = minX + tileSize[0] * res;
    var maxY = minY + tileSize[1] * res;
    var bound = [minX, minY, maxX, maxY];

    var originTileX = 0 + (res * 256) / 2;
    var originTileY = 0 + (res * 256) / 2;

    var centerX = (bound[0] + bound[2]) / 2;
    var centerY = (bound[1] + bound[3]) / 2;

    var x = Math.round(Math.abs((centerX - originTileX) / (res * 256)));
    var y = Math.round(Math.abs((centerY - originTileY) / (res * 256)));
    var z = tileCoord[0];
    return (
      'http://50.73.66.8/PGIS_S_TileMapServer/Maps/default/EzMap?Service=getImage&Type=RGB&Col=' +
      x +
      '&Row=' +
      y +
      '&Zoom=' +
      z +
      '&V=0.3'
    );
  },
};
